package com.ruoyi.common.utils.image;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.io.File;
@Component
public class PathUtil {
    public static final String separator = System.getProperty("file.separator");

    @Value("${ruoyi.profile}")
    private String imgPath;
    /**
     * 获取图片存储的服务器根目录
     * 以windows为例 D:/software/apache-tomcat-8.5.42/upload
     * @return
     */
    // todo 图片根路径
    public String getImageBasePath(){
        String baseImagePath = "";
        if(System.getProperty("os.name").toLowerCase().startsWith("win")){
            baseImagePath = imgPath;
        }else{
            baseImagePath = "/Users/zhoujie/images/";
        }
        return baseImagePath.replace("/",separator);
    }

    //如果目标路径不存在 自动创建
    public void makeDirPath(String targetAddr) {
        String realFileParentPath = getImageBasePath() + targetAddr;
        File dirPath = new File(realFileParentPath);
        boolean a=dirPath.exists();
        if (!dirPath.exists()) {
            dirPath.mkdirs();
        }
    }

}
